package cn.edu.whu.lmars.dblgtree;

import com.vividsolutions.jts.geom.Coordinate;

public class CNode {
	double x ;
	double y;
	float error;
	int seqid;
	
	
	// when isRef true, then the meaning of x and y are refpoint in refkeeper. seqid are ref tree id
	boolean isRef;
	CNode leftChild ;
	CNode rightChild;
	
	public CNode() {
		
	}
	
	public CNode(double x, double y, double error, int seqid) {
		this.x = x;
		this.y = y;
		this.error = (float) error;
		this.seqid = seqid;
		leftChild = null;
		rightChild = null;
	}
	
	// coordinates and constrained points as input
	public static CNode Init(Coordinate[] c, RefList[] cp) {
		
		//handling the constrained case;
		
		
		
		
		for (int i = 0 ; i < cp.length; i++) {
			
		}
		
		
		return null;
	}
	
	//balance the constrained points
	public static CNode bacon(Coordinate[] cp, RefList[] c, int i, int j) {
		if (i == j || i + 1 == j) return null;
		int mid = (i+j) / 2;
		if (mid != i) {
    		CNode cn = new CNode(cp[mid].x, cp[mid].y, Float.MAX_VALUE, mid - i);
    		cn.leftChild = bacon(cp, c, i, mid) ;
    		cn.rightChild = bacon(cp, c, mid, j);
    		//
    		
    		return cn;
		}
		return null;
	}
	
	//
	public static CNode simplify() {
		
		
		return null;
	}
	
	//simplify with constraint
	public static CNode SimpWithCons() {
		return null;
	}
}
